package com.fxkj.cloud.drms.infra.ws;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * <p>Description: </p>
 *
 * @author Wei, Wu
 * @create 2024/11/28 17:15
 */
@Configuration
@EnableWebSocket
public class FxWebSocketConfig implements WebSocketConfigurer {
    private final FxWsClientImpl fxWsClientImpl;

    public FxWebSocketConfig(FxWsClientImpl fxWsClientImpl) {
        this.fxWsClientImpl = fxWsClientImpl;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(fxWsClientImpl, "/ws/msg")
                .addInterceptors(new UserInfoHandshakeInterceptor())
                .setAllowedOrigins("*");
    }
}
